clear all

use "./macro3.dta" // 

gen leftb = lnrzb - lnqyb
gen rightb = ln(rib/qib)
gen lnqib = ln(qib)

gen lefts = lnrzs - lnqys
gen rights = ln(ris/qis)
gen lnqis = ln(qis)

gen leftp = lnrzp - lnqyp
gen rightp = ln(rip/qip)
gen lnqip = ln(qip)

gen lnxrjpy = ln(xrjpy)
gen lnagrawim = ln(agrawim)

gen lnfceg = ln(fceg)
gen lnfoodim = ln(foodim)
gen lnfoodex = ln(foodex)
gen lnimlm = ln(imlm)

tsset year

*Bovine
* dfuller won't reject nonstationarity, so take the difference for stationarity
ivreg2 d.leftb (d.rightb = d.lnqib l.lnqip), endog(d.rightb) robust
* exogeneity is NOT rejected, so use OLS
reg d.leftb d.rightb, robust
* report dwstat
nlcom 1-_b[d.rightb]

*Swine
* dfuller won't reject nonstationarity, so take the difference for stationarity
ivreg2 d.lefts (d.rights = d.lnqis d.lnqib), endog(d.rights) robust
* exogeneity is rejected, so use IV
reg d.lefts d.rights, robust
* report dwstat ivactest
nlcom 1-_b[d.rights]

*Poultry
* dfuller won't reject nonstationarity, so take the difference for stationarity
ivreg2 d.leftp (d.rightp = d.lnqip d.lnxrjpy), endog(d.rightp) robust
* exogeneity is rejected, so use IV
reg d.leftp d.rightp, robust
* report dwstat ivactest
nlcom 1-_b[d.rightp]


*Poultry0 (FEENSTRA only)
* dfuller won't reject nonstationarity, so take the difference for stationarity
ivreg2 d.leftp (d.rightp0 = d.lnqip0 d.lnxrjpy), endog(d.rightp0) robust
* exogeneity is rejected, so use IV
reg d.leftp d.rightp0, robust
* report dwstat ivactest
nlcom 1-_b[d.rightp0]
